
#include <window/window.hpp>
#include <input/inputSingleton.h>

sf::RenderWindow * g_window;

void create_window( size_t width, size_t height, size_t bpp, std::string const & name )
{
	sf::WindowSettings settings;
	settings.StencilBits = 0;
	settings.DepthBits = 0;
	settings.AntialiasingLevel = 2;

	g_window = new sf::RenderWindow( sf::VideoMode( width, height, bpp ), name, sf::Style::Close|sf::Style::Titlebar, settings );
	g_window->UseVerticalSync( true );
	g_window->SetFramerateLimit( 60 );
	g_window->PreserveOpenGLStates( true );
	g_window->EnableKeyRepeat( false );
}

void poll_events( )
{
	sf::Event e;
	while ( g_window->GetEvent( e ) )
	{
		switch ( e.Type )
		{
			case sf::Event::Closed:
			{
				g_window->Close( );
			}
			break;
			case sf::Event::KeyPressed:
			{
				g_user_input.keyInput(true, e.Key.Code);
			}
			break;
			case sf::Event::KeyReleased:
			{
				g_user_input.keyInput(false, e.Key.Code);
			}
			break;
		}
	};
}

void destroy_window( )
{
	delete g_window;
}
